package com.wh.springbootssm.controller;

import com.wh.springbootssm.baseresult.UserResult;
import com.wh.springbootssm.pojo.User;
import com.wh.springbootssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

/**
 * @Auther: HuiEr
 * @Date: 2020/2/21 18:25
 * @Description
 */
@Controller
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("test")
    public UserResult test(int id){
        UserResult userResult = new UserResult();
        userResult.setCode(0);
        User user = userService.findUserById(id);
        userResult.setUser(user);
        return userResult;
    }


    @RequestMapping("test1")
    public String test1(Model model){
        model.addAttribute("username","铁蛋");
        User user = new User(1, "xiaoboboname", "xiaobobopaww",18);
        model.addAttribute("user",user);
        ArrayList<User> users = new ArrayList<>();
        for(int i=0;i<10;i++){
            users.add(new User(i,user.getName()+i,user.getPassword()+i,user.getAge()+1));
        }
        model.addAttribute("users",users);
        return "bobo";
    }
}
